#include "chooselevelsence.h"
#include"QMenuBar"
#include"qpainter.h"
#include"mypushbutton.h"
#include"qdebug.h"
#include"qlabel.h"
ChooseLevelSence::ChooseLevelSence(QWidget *parent) : QMainWindow(parent)
{
    setFixedSize(320,588);
    setWindowIcon(QIcon(":/res/Coin0001.png"));
    setWindowTitle("choose");
    QMenuBar* menubar=menuBar();
    setMenuBar(menubar);
    QMenu* startmenu=menubar->addMenu("start");
    QAction* quitaction=startmenu->addAction("quit");
    connect(quitaction,&QAction::triggered,[=](){
        this->close();
    });

    MyPushButton * backButton=new MyPushButton(":/res/BackButton.png",":/res/BackButtonSelected .png");
    backButton->setParent(this);
    backButton->move(this->width()-backButton->width(),this->height()-backButton->height());
    connect(backButton,&MyPushButton::clicked,[=](){
        qDebug()<<"quit";
        emit this->choosesceneback();
    });

    for(int i=0;i<20;i++)
    {
        MyPushButton * menuBtn=new MyPushButton(":/res/LevelIcon.png");
        menuBtn->setParent(this);
        menuBtn->move(30+i%4*70, 120+i/4*70);

      // menuBtn->setText(QString::number(i));
       QLabel* label=new QLabel;
        label->setParent(menuBtn);
       label->setFixedSize(menuBtn->size());
       label->setText(QString::number(i+1));

        connect(menuBtn,&MyPushButton::clicked,[=](){
            qDebug()<<i<<endl;
           FlayScene* play=new FlayScene(i+1);
            this->hide();
           play->show();

           connect(play, &FlayScene::selectLevelScene, [=](){

                          this->show();
                          delete play;

                      });
        });





    }
}

void ChooseLevelSence::paintEvent(QPaintEvent *){
    QPainter painter(this);
    QPixmap pix;
    pix.load(":/res/OtherSceneBg.png");
    painter.drawPixmap(0,0,this->width(),this->height(),pix);
    pix.load(":/res/Title.png");
    pix.scaled(pix.width()*0.5,pix.height()*0.5);
    painter.drawPixmap(this->width()-pix.width()*0.5,30,pix.width(),pix.height(),pix);




}
